package com.ruoyi.netty.utils;

import com.ruoyi.netty.config.MsgPub;
import com.ruoyi.netty.domain.DeviceChannelInfo;
import com.ruoyi.netty.domain.MsgAgreement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhoujun
 */
@Service
public class CacheService {

    @Autowired
    private MsgPub    msgPub;
    @Autowired
    private RedisUtil redisUtil;

    /**
     * 将通道数据广播给指定的主题  主题格式为：message_pub+节点ip+节点端口
     * @param msgAgreement
     */
    public void push(MsgAgreement msgAgreement) {
        DeviceChannelInfo deviceChannelInfo = redisUtil.selectByChannel(msgAgreement.getUserId());
        if (deviceChannelInfo == null) {
            return;
        }
        //msgPub.pushMessage("message_pub"+deviceChannelInfo.getIp()+deviceChannelInfo.getPort(), msgAgreement);
        msgPub.pushMessage("message_pub", msgAgreement);
    }

    public RedisUtil getRedisUtil() {
        return redisUtil;
    }
}
